<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <my-grandfather></my-grandfather>
    </div>

    <!-- 爷爷组件 -->
    <template id="greadfather">
        <div>
            <h1>我是爷爷组件</h1>
            <button @click="rem">传递</button>
            <my-father v-if="flag"></my-father>
            
        </div>
    </template>

    <!-- 父亲组件 -->
    <template id="father">
        <div>
            <h3>父亲组件</h3>
        </div>
    </template>

   
    <script src="./vue.js"></script>
    <script>


        //父亲
        const Father = {
            template: "#father",
            data(){
                return{
                    timer:null
                }
            },
            mounted(){
              this.timer=  setInterval(()=>{
                    console.log(1);
                },1000)
            },
            beforeDestroy(){
                console.log("我要销毁了")
                clearInterval(this.timer)
            },
            destroyed(){
                console.log("销毁完毕")
            }
        }
        /*   const Father = {
            template: "#father",
         
            beforeDestroy() {
                console.log("我要销毁了")
                
            },
            destroyed() {
                console.log('销毁完毕')
            }
        } */
        //爷爷
        const GrandFather = {
            template: "#greadfather",
            components: {
                "my-father": Father
            },
            data(){
                return {
                    flag:true
                }
            },
            methods:{
                rem(){
                    this.flag=false
                }
            }
            
        }

        new Vue({
            el: "#app",
            components: {
                "my-grandfather": GrandFather
            }
        })
    </script>
</body>

</html>